<style type="text/css" title="currentStyle">
	@import "../media/css/demo_page.css";
	@import "../media/css/demo_table_jui.css";
	@import "../examples_support/themes/smoothness/jquery-ui-1.8.4.custom.css";
	@import "media/css/TableTools_JUI.css";
</style>
<script type="text/javascript" charset="utf-8" src="../media/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/ZeroClipboard.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/TableTools.js"></script>
<script type="text/javascript" charset="utf-8">
	$(document).ready( function () {
		$('#tableResller').dataTable( {
			"bJQueryUI": true,
			"sPaginationType": "full_numbers",
			"sDom": 'Tlfrtip',
			"oTableTools": {
				"aButtons": [
					"copy", "csv", "xls", "pdf", "print",
					{
						"sExtends":    "collection",
						"sButtonText": "Save",
						"aButtons":    [ "csv", "xls", "pdf" ]
					}
				]
			}
		} );
		$('#tableClient').dataTable( {
			"bJQueryUI": true,
			"sPaginationType": "full_numbers",
			"sDom": '<"H"Tfr>t<"F"ip>',
			"oTableTools": {
				"aButtons": [
					"copy", "csv", "xls", "pdf", "print",
					{
						"sExtends":    "collection",
						"sButtonText": "Save",
						"aButtons":    [ "csv", "xls", "pdf" ]
					}
				]
			}
		} );
	} );
</script><?php
$sql = "SELECT * FROM tb_clientinfo where ci_clientId =0 ORDER BY ci_clientName DESC";
$rows = $db->query($sql);
?>
<script language="javascript">
function funEditUser(uid)
{
	document.frmSubmit.txtClientId.value = uid;
	document.frmSubmit.action = '?ch=addClient';
	document.frmSubmit.submit();
}
</script>
<div class="listofusers"> Total - Resellers : <?php echo $db->affected_rows;?></div>
<table cellpadding="0" cellspacing="0" border="0" class="gridform_final" id="tableResller">
  <thead>
    <tr>
        <th>Reseller Name   </th>
        <th>Phone 1</th>
        <th>Phone 2</th>
        <th>Email 1</th>
        <th>Email 2</th>
        <th>Tot. Clients</th> 
        <th>Tot. Devices</th>
        <th>Edit</th>
   </tr>
   </thead>
   <tbody>
   <?php
   if($db->affected_rows > 0)
   {
   	while ($record = $db->fetch_array($rows)) 
	{
		   $getResellDev = "select * from tb_deviceinfo,tb_clientinfo where di_clientId = ci_id AND ci_clientId = ".$record[ci_id];
		   $resResellDev = $db->query($getResellDev);
		   $totDev = $db->affected_rows;
		   
		   $getResellClient = "select * from tb_clientinfo where ci_clientId = ".$record[ci_id];
		   $resResellClient = $db->query($getResellClient);
		   $totClient = $db->affected_rows;
	?>
		<tr>
        <td><?php echo ucfirst($record[ci_clientName]);?></td>
        <td><?php echo $record[ci_phoneNumber];?> </td>
        <td><?php echo $record[ci_mobileNumer];?> </td>
        <td><a href="mailto:<?php echo $record[ci_email1];?>"><?php echo $record[ci_email1];?></a></td>
        <td><a href="mailto:<?php echo $record[ci_email2];?>"><?php echo $record[ci_email2];?></a></td>
        <td><?php echo $totClient;?> </td>
        <td><?php echo $totDev;?> </td>        
        <td><a href="#" onclick="funEditUser('<?php echo $record[ci_id];?>')">Edit</a></span></td>
   </tr>
   <?php
   	$avail = 0;
	}
	}
   ?>
   </tbody>
</table>
<?php
	$sql = "SELECT * FROM tb_clientinfo  where ci_clientId !=0 ORDER BY ci_clientName DESC";
	$rows = $db->query($sql);
?>
<div class="listofusers"><strong>Total - Client : <?php echo $db->affected_rows;?></strong></div>
<table cellpadding="0" cellspacing="0" border="0" class="gridform_final" id="tableClient">
  <thead>
    <tr>
        <th>Client Name   </th>
        <th>Reseller Name   </th>
        <th>Phone 1</th> 
        <th>Phone 2</th>
        <th>Email 1</th>
        <th>Email 2</th>
        <th>Limit</th>
        <th>Edit</th>
   </tr>
   </thead>
   <tbody>
   <?php
  
   if($db->affected_rows > 0)
   {
   	while ($record = $db->fetch_array($rows)) 
	{
		$getDeviceCount = "SELECT * FROM tb_deviceinfo WHERE di_clientId = ".$record[ci_id];
		$rowCount = $db->query($getDeviceCount);
		$avail = $db->affected_rows;
		
		if($record[ci_clientId] != 0)
		{
		$getClient = "SELECT ci_clientName FROM tb_clientinfo WHERE ci_id = ".$record[ci_clientId];
	    $rowClient = $db->query($getClient);
		$recordClient = $db->fetch_array($rowClient);
		$cltName = $recordClient[ci_clientName];
		}
		else $cltName = "Nil";
		
	?>
		<tr>
        <td><?php echo ucfirst($record[ci_clientName]);?></td>
        <td><?php echo ucfirst($cltName);?></td>
        <td><?php echo $record[ci_phoneNumber];?> </td>
        <td><?php echo $record[ci_mobileNumer];?> </td>
        <td><a href="mailto:<?php echo $record[ci_email1];?>"><?php echo $record[ci_email1];?></a></td>
        <td><a href="mailto:<?php echo $record[ci_email2];?>"><?php echo $record[ci_email2];?></a></td>
        <td><?php echo $avail;?> </td>
        <td><a href="#" onclick="funEditUser('<?php echo $record[ci_id];?>')">Edit</a></span></td>
   </tr>
   <?php
	}
	}
   ?>
   </tbody>
</table>
</div>

<form name="frmSubmit" id="frmSubmit" method="post">
	<input type="hidden" name="txtClientId" id="txtClientId" />
</form>